'''
Created on Jul 25, 2013

@author: Cihat Basol
'''


import time

import dexen
from dexen import remoting
from dexen.common.events import (JobStartedEvent, JobStoppedEvent,
                                 PeriodicTimeEvent)
from dexen.common import utils
from dexen.client.api import ServerAPI, JobAPI
from dexen.common.task import EventTask, DataFlowTask



def main():
    server = ServerAPI(username="deneme", password="deneme", 
                       url="localhost", port=5000)
    assert isinstance(server, ServerAPI)
    job = server.create_job("JOB33")
    #job = server.get_job("JOB20")
    assert isinstance(job, JobAPI)
    
    #print job.get_executions(1.534)
    
    start_time = time.time()
    
    utils.zipfolder("deneme", "python/HelloWorld", include_rootdir=False)
    
    job.upload("deneme.zip")
    
    task1 = EventTask("HelloTask", ["python", "main.py"], PeriodicTimeEvent(1))
    job.register_task(task1)

    job.run()
    last_update = 0.0
    for _ in xrange(12): 
        time.sleep(5)
        for execution in job.get_executions(last_update):
            print "-------------- Execution ---------------"
            for key, value in execution.iteritems():
                print "{0}: {1}".format(key, value)
            print ""
        last_update = time.time()
    job.stop()
    

if __name__ == '__main__':
    main()























